home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / eepic.trm (.txt) < prev    next >
LaTeX Document  |  1993-09-15  |  8KB  |  214 lines

  1.  * $Id: eepic.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  2. /* GNUPLOT - eepic.trm */
  3.  * Copyright (C) 1990 - 1993   
  4.  * Permission to use, copy, and distribute this software and its
  5.  * documentation for any purpose with or without fee is hereby granted, 
  6.  * provided that the above copyright notice appear in all copies and 
  7.  * that both that copyright notice and this permission notice appear 
  8.  * in supporting documentation.
  9.  * Permission to modify the software is granted, but not the right to
  10.  * distribute the modified code.  Modifications are to be distributed 
  11.  * as patches to released version.
  12.  * This software  is provided "as is" without express or implied warranty.
  13.  * This file is included by ../term.c.
  14.  * This terminal driver supports:
  15.  *   The EEPIC macros for LaTeX. 
  16.  * AUTHORS
  17.  *   David Kotz
  18.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  19.  *  This file contains the eepic terminal driver, intended for use with the 
  20.  *  eepic.sty macro package for LaTeX. This is an alternative to the 
  21.  *  latex driver. You need eepic.sty, epic.sty, and a printer driver that
  22.  *  supports the tpic \specials.
  23.  * Although dotted and dashed lines are possible with EEPIC, and are
  24.  * tempting, they do not work well for high-sample-rate curves, mushing
  25.  * the dashes all together into a solid line. For now anyway, the EEPIC
  26.  * driver will have only solid lines. Anyone got a solution?
  27.  * LATEX must also be defined.
  28. #define EEPIC_PTS_PER_INCH (72.27)
  29. #define DOTS_PER_INCH (300)    /* resolution of printer we expect to use */
  30. #define EEPIC_UNIT (EEPIC_PTS_PER_INCH/DOTS_PER_INCH) /* dot size in pt */
  31. /* 5 inches wide by 3 inches high (default) */
  32. #define EEPIC_XMAX (5*DOTS_PER_INCH)  /* (EEPIC_PTS_PER_INCH/EEPIC_UNIT*5.0) */
  33. #define EEPIC_YMAX (3*DOTS_PER_INCH)  /* (EEPIC_PTS_PER_INCH/EEPIC_UNIT*3.0) */
  34. #define EEPIC_HTIC (5*DOTS_PER_INCH/72)        /* (5./EEPIC_UNIT) */
  35. #define EEPIC_VTIC (5*DOTS_PER_INCH/72)        /* (5./EEPIC_UNIT) */
  36. #define EEPIC_HCHAR (DOTS_PER_INCH*53/10/72)    /* (5.3/EEPIC_UNIT) */
  37. #define EEPIC_VCHAR (DOTS_PER_INCH*11/72)    /* (11./EEPIC_UNIT) */
  38. static unsigned int EEPIC_posx;
  39. static unsigned int EEPIC_posy;
  40. enum JUSTIFY eepic_justify=LEFT;
  41. static int eepic_angle=0;
  42. /* for DOTS point style */
  43. #define EEPIC_TINY_DOT "\\rule{.1pt}{.1pt}"
  44. /* POINTS */
  45. #define EEPIC_POINT_TYPES 12    /* we supply more point types */
  46. static char GPFAR * GPFAR EEPIC_points[] = {
  47.     "\\raisebox{-1.2pt}{\\makebox(0,0){$\\Diamond$}}",
  48.     "\\makebox(0,0){$+$}",
  49.     "\\raisebox{-1.2pt}{\\makebox(0,0){$\\Box$}}",
  50.     "\\makebox(0,0){$\\times$}",
  51.     "\\makebox(0,0){$\\triangle$}",
  52.     "\\makebox(0,0){$\\star$}",
  53.     "\\circle{12}", "\\circle{18}", "\\circle{24}",
  54.     "\\circle*{12}", "\\circle*{18}", "\\circle*{24}"
  55. /* LINES */
  56. #define EEPIC_NUMLINES 5        /* number of linetypes below */
  57. static char GPFAR * GPFAR EEPIC_lines[] = {
  58.     "\\thicklines \\path",            /* -2 border */
  59.     "\\thinlines \\drawline[-50]",        /* -1 axes */
  60.     "\\thinlines \\path",            /*  0 solid thin  */
  61.     "\\thicklines \\path",            /*  1 solid thick */
  62.     "\\Thicklines \\path",            /*  2 solid Thick */
  63. /* These are other possibilities
  64.     "\\thinlines \\dottedline{30}",
  65.     "\\thinlines \\drawline[-30]",    
  66.     "\\thinlines \\dottedline{60}",
  67.     "\\thinlines \\drawline[-60]",    
  68.     "\\thinlines \\dashline[-10]{20}[6]"
  69. static int EEPIC_type;        /* current line type */
  70. static TBOOLEAN EEPIC_inline = FALSE; /* are we in the middle of a line */
  71. static void EEPIC_endline();    /* terminate any line in progress */
  72. static int EEPIC_linecount = 0; /* number of points in line so far */
  73. #define EEPIC_LINEMAX 50        /* max value for linecount */
  74. /* ARROWS */
  75. /* we use the same code as for LATEX */
  76. static void best_latex_arrow(); /* figure out the best arrow */
  77. EEPIC_init()
  78.     EEPIC_posx = EEPIC_posy = 0;
  79.     EEPIC_linetype(-1);
  80.     fprintf(outfile, "%% GNUPLOT: LaTeX picture using EEPIC macros\n");
  81.     fprintf(outfile, "\\setlength{\\unitlength}{%fpt}\n", EEPIC_UNIT);
  82. EEPIC_scale(xs, ys)
  83.     double xs, ys;            /* scaling factors */
  84.     register struct termentry *t = &term_tbl[term];
  85.     /* we change the table for use in graphics.c and EEPIC_graphics */
  86.     t->xmax = (unsigned int)(EEPIC_XMAX * xs);
  87.     t->ymax = (unsigned int)(EEPIC_YMAX * ys);
  88.     return(TRUE);
  89. EEPIC_graphics()
  90.     register struct termentry *t = &term_tbl[term];
  91.     fprintf(outfile, "\\begin{picture}(%d,%d)(0,0)\n", t->xmax, t->ymax);
  92.     fprintf(outfile, "\\tenrm\n");
  93. EEPIC_text()
  94.     EEPIC_endline();
  95.     fprintf(outfile, "\\end{picture}\n");
  96. EEPIC_linetype(linetype)
  97.     int linetype;
  98.     EEPIC_endline();
  99.     if (linetype >= EEPIC_NUMLINES-2)
  100.      linetype %= (EEPIC_NUMLINES-2);
  101.     EEPIC_type = linetype;
  102. EEPIC_move(x,y)
  103.     unsigned int x,y;
  104.     EEPIC_endline();
  105.     EEPIC_posx = x;
  106.     EEPIC_posy = y;
  107. EEPIC_point(x,y, number)        /* version of line_and_point */
  108.     unsigned int x,y;
  109.     int number;                /* type of point */
  110.     EEPIC_move(x,y);
  111.     /* Print the character defined by 'number'; number < 0 means 
  112.       to use a dot, otherwise one of the defined points. */
  113.     fprintf(outfile, "\\put(%d,%d){%s}\n", x, y, 
  114.           (number < 0 ? EEPIC_TINY_DOT
  115.            : EEPIC_points[number % EEPIC_POINT_TYPES]));
  116. EEPIC_vector(ux,uy)
  117.     unsigned int ux,uy;
  118.     if (!EEPIC_inline) {
  119.        EEPIC_inline = TRUE;
  120.        /* Start a new line. This depends on line type */
  121.        fprintf(outfile, "%s(%u,%u)", 
  122.              EEPIC_lines[EEPIC_type+2], 
  123.              EEPIC_posx, EEPIC_posy);
  124.        EEPIC_linecount = 1;
  125.     } else {
  126.        /* Even though we are in middle of a path, 
  127.         * we may want to start a new path command. 
  128.         * If they are too long then latex will choke.
  129.         */
  130.        if (EEPIC_linecount++ >= EEPIC_LINEMAX) {
  131.           fprintf(outfile, "\n");
  132.           fprintf(outfile, "%s(%u,%u)", 
  133.                 EEPIC_lines[EEPIC_type+2], 
  134.                 EEPIC_posx, EEPIC_posy);
  135.           EEPIC_linecount = 1;
  136.        }
  137.     }
  138.     fprintf(outfile, "(%u,%u)", ux,uy);
  139.     EEPIC_posx = ux;
  140.     EEPIC_posy = uy;
  141. static void
  142. EEPIC_endline()
  143.     if (EEPIC_inline) {
  144.        fprintf(outfile, "\n");
  145.        EEPIC_inline = FALSE;
  146.     }
  147. EEPIC_arrow(sx,sy, ex,ey, head)
  148.     int sx,sy, ex,ey;
  149.     TBOOLEAN head;
  150.     best_latex_arrow(sx,sy, ex,ey, 2, head); /* call latex routine */
  151.     EEPIC_posx = ex;
  152.     EEPIC_posy = ey;
  153. EEPIC_put_text(x, y, str)
  154.     int x,y;                /* reference point of string */
  155.     char str[];            /* the text */
  156.     EEPIC_endline();
  157.     fprintf(outfile, "\\put(%d,%d)",x,y);
  158.     switch(eepic_angle) {  
  159.         case 0: {
  160.           switch(eepic_justify) {
  161.              case LEFT: {
  162.                 fprintf(outfile,
  163.                        "{\\makebox(0,0)[l]{%s}}\n", str);
  164.                 break;
  165.              }
  166.              case CENTRE: {
  167.                 fprintf(outfile,
  168.                        "{\\makebox(0,0){%s}}\n", str);
  169.                 break;
  170.              }
  171.              case RIGHT: {
  172.                 fprintf(outfile,
  173.                        "{\\makebox(0,0)[r]{%s}}\n", str);
  174.                 break;
  175.              }
  176.           }
  177.           break;
  178.        }
  179.        case 1: {            /* put text in a short stack */
  180.           switch(eepic_justify) {
  181.              case LEFT: {
  182.                 fprintf(outfile,
  183.                        "{\\makebox(0,0)[lb]{\\shortstack{%s}}}\n", str);
  184.                 break;
  185.              }
  186.              case CENTRE: {
  187.                 fprintf(outfile,
  188.                        "{\\makebox(0,0)[l]{\\shortstack{%s}}}\n", str);
  189.                 break;
  190.              }
  191.              case RIGHT: {
  192.                 fprintf(outfile,
  193.                        "{\\makebox(0,0)[lt]{\\shortstack{%s}}}\n", str);
  194.                 break;
  195.              }
  196.           }
  197.           break;
  198.        }    
  199.     }
  200. int EEPIC_justify_text(mode)
  201.     enum JUSTIFY mode;
  202.     eepic_justify = mode;
  203.     return (TRUE);
  204. int EEPIC_text_angle(angle)
  205.     int angle;
  206.     /* we can't really write text vertically, but this will 
  207.       put the ylabel centred at the left of the plot, and
  208.       then we'll make a \shortstack */
  209.     eepic_angle = angle;
  210.     return (TRUE);
  211. EEPIC_reset()
  212.     EEPIC_endline();
  213.     EEPIC_posx = EEPIC_posy = 0;
  214.